<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>

<title>Custom List</title>

	<script type="text/javascript">
		
		var maxItemIndex = ${itemsSize-1};
		
		
		function changeRow()
      	{
         var custom_lists = $('#custom_lists');
			
         
		 custom_lists.moveRow(1,2);
         //custom_lists.moveRow(0, custom_lists.rows.length-1) 
      	}
      
		function add(){
			

			//var custom_lists = $('#custom_lists');
			var custom_lists = document.getElementById('custom_lists');
			
			var row = custom_lists.insertRow(custom_lists.rows.length); 
			
			var cell_value    = row.insertCell(row.cells.length);
			var cell_value2    = row.insertCell(row.cells.length);
			var cell_uniqueId = row.insertCell(row.cells.length);
			var cell_abbr     = row.insertCell(row.cells.length); 
			var cell_min     = row.insertCell(row.cells.length); 
			var cell_max     = row.insertCell(row.cells.length); 			
			var cell_inactive = row.insertCell(row.cells.length);
			var cell_sequence = row.insertCell(row.cells.length);
			
			maxItemIndex++;
			cell_value.innerHTML    = "<input type='text' name='item.items["+maxItemIndex+"].value' size='30'/>";
			cell_value2.innerHTML    = "<input type='text' name='item.items["+maxItemIndex+"].value2' size='35'/>";
			cell_uniqueId.innerHTML = "<input type='text' name='item.items["+maxItemIndex+"].uniqueId' size='3'/>";
			cell_abbr.innerHTML     = "<input type='text' name='item.items["+maxItemIndex+"].abbr' size='20'/>";
			cell_min.innerHTML     = "<input type='text' name='item.items["+maxItemIndex+"].min' size='8'/>";
			cell_max.innerHTML     = "<input type='text' name='item.items["+maxItemIndex+"].max' size='7'/>";
			cell_inactive.innerHTML = "<input type='checkbox' name='item.items["+maxItemIndex+"].inactive' value='true'/>";
			cell_sequence.innerHTML = "<input type='text' name='item.items["+maxItemIndex+"].sequence'  size='2'/>";
		
		}
	</script>
</head>

<body>

<s:if test="item.id!=null">
    Edit
</s:if>
<s:else>
    Create
</s:else>


<s:form action="save" theme="simple" >
	
	<s:hidden name="id"/>
    
    
	
	
	<table width="321" border="1">
	  <tr>
		<td width="91">Name</td>
		<td width="214"><s:textfield name="item.name"/></td>
	  </tr>
	  <tr>
		<td>Abbreviation</td>
		<td><s:textfield name="item.abbr"/></td>
	  </tr>
	  <tr>
		<td colspan="2" align="left">
		<div class="ctrls">
		<s:submit value="Save" name="Save"/>
		<s:submit value="Cancel" name="redirect-action:list"/>
		</div>
		</td>
	  </tr>
	  
  </table>
	
	
	
	

	<table width="991" cellspacing="2" id="custom_lists">
	<thead>
	  <tr>
	    <th width="250">Value</th>
	    <th width="132">Value 2</th>
	    <th width="96">ID</th>
	    <th width="240">Abbreviation</th>
	    <th width="73">Min</th>
	    <th width="90">Max</th>
	    <th width="73">Inactive</th>
	    <th width="90">Sequence</th>
	    <th width="70">Delete</th>
	  </tr>
	 </thead>
	  <tbody>
	  <s:iterator value="item.items"  status="stat">
	  <tr id="idx_${idx}">
	    <td><s:textfield name="%{'item.items['+#stat.index+'].value'}" size="30"/></td>
	    <td><s:textfield name="%{'item.items['+#stat.index+'].value2'}" size="35"/></td>
	    <td><s:textfield name="%{'item.items['+#stat.index+'].uniqueId'}" size="3"/></td>
	    <td><s:textfield name="%{'item.items['+#stat.index+'].abbr'}" size="20"/></td>
	    <td><s:textfield name="%{'item.items['+#stat.index+'].min'}" size="8"/></td>
	    <td><s:textfield name="%{'item.items['+#stat.index+'].max'}" size="7"/></td>
	    <td><s:checkbox name="%{'item.items['+#stat.index+'].inactive'}"/></td>
	    <td><s:textfield name="%{'item.items['+#stat.index+'].sequence'}" size="2"/></td>
	    <td>
		    <s:url id="deleteItem" action="deleteItem" includeParams="none">
				<s:param name="itemId" value="id" />
				<s:param name="id" value="item.id" />
			</s:url>
		   <s:a href="%{#deleteItem}">Delete</s:a>
	    </td>
	  </tr>
	  </s:iterator>
	  </tbody>
  </table>
	

</s:form>
<div class="ctrls">
<input type="button" value="Add" onClick="add()" align="left"/>
</div>


</body>
</html>


